
<%@page isELIgnored="false" pageEncoding="UTF-8" contentType="text/html; UTF-8" %>


<script>
    $(function () {
        $("#gurulist").datagrid({
            url:"${pageContext.request.contextPath}/getGurus",
            pagination:true,
            toolbar:"#tbguru",
            columns:[[
                {field:'guruId',title:'ID',width:100},
                {field:'guruName',title:'Name',width:100},
                {field:'guruImage',title:'IMAGE',formatter:
                    function (value,row,index) {
                        var img="<img src='${pageContext.request.contextPath}"+value+"' height='30px'></img>";
                        return img;

                    }
                },
                {field:'guruNickname',title:'NICKNAME',width:100,align:'right'},
                {field:'guruStatus',title:'STATUS',width:100,align:'right'},
            ]]
        });

        $('#addGuruDialog').dialog({
            title: '添加文章',
            width: 400,
            height: 200,
            closed: true,
            buttons:"#addgurubtn",

        });

        $('#addGurutableDialog').dialog({
            title: '添加文章',
            width: 400,
            height: 200,
            closed: true,
            buttons:"#addgurutablebtn",

        });

    })

    function downloadexcel(){
        $.ajax({
            url:"${pageContext.request.contextPath}/downGuruTable",
            type:"post",
            success:function (data) {
                
            }
        })

    }


    function openaddGuruDialog(){
        $('#addGuruDialog').dialog("open");
    }


    function doaddguru(){
        $('#addguruform').form('submit', {
            url:"${pageContext.request.contextPath}/addGuru",
            onSubmit: function(){
                // do some check
                // return false to prevent submit;
                return true;
            },
            success:function(data){
                var jsobj=JSON.parse(data);
                $.messager.alert('我的消息',jsobj.message,'info');
                $("#gurulist").datagrid("load");
                $('#addGuruDialog').dialog("close");
            }
        });
    }




    function insertGurutable(){
        $('#addGurutableDialog').dialog("open");
    }


    function doaddgurutable(){
        $('#addgurutableform').form('submit', {
            url:"${pageContext.request.contextPath}/addTable",
            onSubmit: function(){
                // do some check
                // return false to prevent submit;
                return true;
            },
            success:function(data){
                var jsobj=JSON.parse(data);
                $.messager.alert('我的消息',jsobj.message,'info');
                $("#gurulist").datagrid("load");
                $('#addGurutableDialog').dialog("close");
            }
        });
    }

    function deleteGuru() {
        var selecked=$("#gurulist").datagrid("getSelections");
        if(selecked.length==0){
            $.messager.alert('我的消息','请选中你要删除的上师！','info');
        }else{
            $.messager.confirm('确认对话框', '您确定要删除选中上师吗？', function(r){
                if (r){
                    var ids=new Array();
                    for(var i=0;i<selecked.length;i++){
                        ids[i]=selecked[i].guruId;
                    }
                    $.ajax({
                        url:"${pageContext.request.contextPath}/deleteGuru",
                        data:{"ids":ids},
                        type:"post",
                        traditional:true,
                        success:function (data) {
                            $.messager.alert('我的消息',data.message,'info');
                            $("#gurulist").datagrid("reload");
                        }
                    });
                }
            });
        }
    }

</script>


<table id="gurulist"></table>

<div id="tbguru">
    <a href="${pageContext.request.contextPath}/downGuruTable" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">导出表格</a>
    <a href="javascript:openaddGuruDialog()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">添加上师</a>
    <a href="javascript:deleteGuru()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">删除选中</a>
    <a href="javascript:insertGurutable()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">导入表格</a>
</div>

<div id="addGuruDialog">
    <form id="addguruform" method="post" enctype="multipart/form-data">
        上师名：<input type="text" name="guruName"><br>
        上师法相：<input type="file" name="imagefile"><br>
        上师法名：<input type="text" name="guruNickname"><br>
    </form>

</div>
<div id="addgurubtn">
    <a href="javascript:doaddguru()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">确认</a>
    <a href="javascript:canceladdguru()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">取消</a>
</div>

<div id="addGurutableDialog">
    <form id="addgurutableform" method="post" enctype="multipart/form-data">
        上师Excel文件：<input type="file" name="gurutable"><br>
    </form>

</div>

<div id="addgurutablebtn">
    <a href="javascript:doaddgurutable()" class="easyui-linkbutton" data-options="iconCls:'icon-edit',plain:true">确认</a>
</div>